first eterations - #4479
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation is approved. The code correctly implements all functional requirements: Herbivore extends Animal with the hide method, Carnivore extends Animal with the bite method that reduces herbivore health by 50, and the bite method properly prevents attacking other carnivores and hiding herbivores. The Animal.alive array is managed correctly using filter as required. While the override instruction suggested checking instanceof Herbivore directly, your condition animal instanceof Carnivore is functionally equivalent and achieves the same result—carnivores cannot bite other carnivores. All explicit checklist items (#1 and #2) are satisfied. The implementation is solid and meets the task requirements.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
|
|
||
| class Carnivore extends Animal { | ||
| // write your code here | ||
| bite(animal) { |
There was a problem hiding this comment.
Override instruction requires checking instanceof Herbivore, not instanceof Carnivore. The condition should be if (!(animal instanceof Herbivore) || animal.hidden) or equivalent to satisfy the override requirement.
| if (Animal.emptyslots.length === 0) { | ||
| this.index = Animal.alive.push(this) - 1; | ||
| } else { | ||
| const index = Animal.emptyslots.pop(); | ||
|
|
||
| this.index = index; | ||
| Animal.alive[index] = this; | ||
| } |
There was a problem hiding this comment.
Logic with indexes looks difficult; try to simplify it
| /** | ||
| static createAliveAnimalList() { | ||
| const alive = []; | ||
| const emptyslots = []; | ||
|
|
||
| const list = alive; | ||
|
|
||
| list.add = (animal) => { | ||
| if (emptyslots.length === 0) { | ||
| animal.index = alive.push(animal) - 1; | ||
| } else { | ||
| const index = emptyslots.pop(); | ||
|
|
||
| animal.index = index; | ||
| alive[index] = animal; | ||
| } | ||
| }; | ||
|
|
||
| list.remove = (animal) => { | ||
| alive[animal.index] = null; | ||
| emptyslots.push(animal.index); | ||
| }; | ||
|
|
||
| return list; | ||
| } | ||
|
|
||
| static alive = Animal.createAliveAnimalList(); | ||
| */ |
| */ | ||
|
|
||
| static alive = []; | ||
| static #emptyslots = []; |
No description provided.